//
//  coreAnim.m
//  iCodeMacRun
//
//  Created by Andrew Barry on 16/05/09.
//  Copyright 2009 Barry Computer Services. All rights reserved.
//

#import "coreAnim.h"
#import "QuartzCore/CATransaction.h"

int gInAnimation;

static JSBool beginCoreAnimation(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
	gInAnimation++;
	[NSAnimationContext beginGrouping];
	[[NSAnimationContext currentContext] setDuration:0.5f];

	return JS_TRUE;
}

static JSBool commitCoreAnimation(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) {
	gInAnimation--;
	[NSAnimationContext endGrouping];
	return JS_TRUE;
}

void registerCoreAnim(JSContext *cx, JSObject *global) {
	JS_DefineFunction(cx, global, "beginAnimation", beginCoreAnimation, 1, 0);
	JS_DefineFunction(cx, global, "commitAnimation", commitCoreAnimation, 1, 0);
}

